package cn.itcast.datasource.druid;

import cn.itcast.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DruidDemo2 {

    public static void main(String[] args) {

        /*
            完成添加操作: 给account添加一条记录
         */
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            //获取连接
            conn = JDBCUtils.getConnection();
            //定义SQL
            String sql = "insert into account values(null, ?, ?)";
            //获取PreparedStatement对象
            pstmt = conn.prepareStatement(sql);
            //给?赋值
            pstmt.setString(1, "wangwu");
            pstmt.setDouble(2,3000);
            //执行SQL
            int count = pstmt.executeUpdate();
            System.out.println(count);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.close(pstmt, null, conn);
        }

    }

}
